<?php


namespace App\Admin\Renderable;


use App\Models\GrGood;
use App\Models\GrGoodsType;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class GoodsTable extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new GrGood(), function (Grid $grid) {
            $grid->model()->where('status',1);

            $grid->column('goods_id', 'ID')->sortable();
            $grid->column('goods_img_cover', '图片')->image('', 100, 100);
            $grid->column('goods_name', '商品名称');
            $grid->column('goods_now_price', '商品价格');
            $grid->column('goods_type_id', '商品分类')->display(function ($e) {
                $data = GrGoodsType::where('goods_type_id', $this->goods_type_id)->pluck('goods_type_name');
                return ($data->toArray())[0];
            })->width(92);
            $grid->column('stock_total', '库存');
            $grid->column('created_at');
            $grid->column('updated_at');

            $grid->quickSearch(['goods_id', 'goods_img_cover', 'goods_type_name']);

            $grid->paginate(10);
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('username')->width(4);
                $filter->like('name')->width(4);
            });
        });
    }

}
